var isMobile = false,
	target = $(".scroll-anchor").offset().top,
	opacity = 0,
	headerH,
	navH;
/*
** 滚动条滚动
*/
function jump(){
	
	var o = (e = location.href).indexOf("#"),e = e.substr(o + 1);
	
	return !(document.onreadystatechange = function() {
		var firstAnchor = $(".subpage-nav-list .subpage-nav-item").eq(0).data('anchor').substr(1);
		console.log('11111',document.readyState)
		// var firstAnchor = $(".subpage-nav-list .subpage-nav-item").eq(0).data('anchor').substr(1);
		if("complete" == document.readyState && -1 != o && firstAnchor != e){
			$("html,body").stop().animate({
				scrollTop: $("#" + e).offset().top
			},500),!1
		} 
	})
}
function scrollFun(e){
	e = e || window.event;
	var t = 0;
	t = window.pageXOffset ? window.pageYOffset : document.body.scrollTop + document.documentElement.scrollTop;
	// t >= 100 ? ($(".header").addClass('header-fixed')) : ($(".header").removeClass('header-fixed'));
	opacity = t / target >= 1 ? 1 : t / target;
	$(".header-bg").css("opacity",opacity);
	
	// tab sticky
	// t >= stickyTop ? $(".step-tab").addClass("fixed") : $(".step-tab").removeClass("fixed");
	scrollNav(t);
	// t >= footerTop ? $(".step-tab").removeClass("fixed") : '';
	// 0 != showHeadState && scrollNav(t);
	
}

function scrollNav(t){
	for(var i = 0;i < $(".section-anchor").length;i++) {
		if(t > $(".section-anchor").eq(i).offset().top - headerH){
			setActive('.nav-other',i);
		}else {
			resetActive('.nav-other',i);
		}
	}
}
/*
** 设置高亮状态
*/
	function setActive(parent,index){
		$(parent).find(".nav-item").eq(index).addClass("active").siblings().removeClass("active");
	}
	function resetActive(parent,index){
		$(parent).find(".nav-item").eq(index).removeClass("active");
	}
$(document).ready(function(){
	setTimeout(function(){
		(headerH = $(".header").outerHeight(),
		navH = $(".nav").outerHeight()),
		window.onscroll = scrollFun,
		$(".nav-other .nav-item a").on('click',function(){
			// return $("html,body").stop().animate({
			// 	scrollTop: $($(this).data('anchor')).offset().top
			// },500);
			if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') && location.hostname === this.hostname) {
			        var target = $(this.hash);
			        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
			        if (target.length) {
			            event.preventDefault();
			            $('html, body').animate({
			                scrollTop: target.offset().top
			            }, 800, 'swing'); // 动画持续时间1000毫秒
						$(".header").removeClass("mobile-menu-open");
						$("body").removeClass("disable-scroll");
			        }
			    }
		}),scrollFun();
		
		
	},100)
	
	
	
	// 移动端导航
	$(".nav-toggle").on('click',function(){
		$(".header").toggleClass("mobile-menu-open");
		$("body").toggleClass("disable-scroll");
	})
	
	
	
	$(document).on('click',function(e){
		var _con=$('.header-language');//设置目标区域使其点击这个区域popup不消失
		if(!_con.is(e.target) && _con.has(e.target).length === 0) { //判断点击事件发生在区域外的条件是：1. 点击事件的对象不是目标区域本身2. 事件对象同时也不是目标区域的子元素
			$(".header-language").removeClass("show-language")
		}
	})
	
	
	
	
})







